package inet.app.controller.parser;

import inet.app.model.object.Member;
import inet.app.model.util.SmartLog;
import android.text.TextUtils;

public class Parser_Member {
	public static Member getMember(String strResult) {
		if(strResult == null || strResult.equals("0")) {
			return null;
		}
		Member objMember = new Member();
		try {
			String[] arrResult = strResult.split("<br/>");
			if(arrResult!=null && arrResult.length>0){
				objMember = new Member();
				for(int i=0;i<arrResult.length;i++){		
					if(TextUtils.isEmpty(arrResult[i])) {
						continue;
					}
					arrResult[i] = arrResult[i].replaceAll("\n","");
					if(arrResult[i].startsWith("id:"))
						objMember.setId(Long.valueOf(arrResult[i].substring(3)));						
					else if(arrResult[i].startsWith("name:"))
						objMember.setFullname(arrResult[i].substring(5));
					else if(arrResult[i].startsWith("email:"))
						objMember.setEmail(arrResult[i].substring(6));
					else if(arrResult[i].startsWith("username:"))
						objMember.setUsername(arrResult[i].substring(9));
					else if(arrResult[i].startsWith("mobile:"))
						objMember.setMobile(arrResult[i].substring(7));
					else if(arrResult[i].startsWith("gender:"))
						objMember.setGender(arrResult[i].substring(6).equals("0")?Member.GENDER_FEMALE:Member.GENDER_MALE);
					else if(arrResult[i].startsWith("birthday:"))
						objMember.setBirthday(arrResult[i].substring(9));
				}					
			}
		} catch(Exception e) {
			SmartLog.e(e.toString());
			objMember = null;
		}
		return objMember;
	}
}
